package 贪心算法;

public class 摆动序列 {
    class Solution{
        public int wiggleMaxLength(int[] nums){
            if (nums==null||nums.length<=1){
                return nums.length;
            }
            int currDiff = 0;
            int preDiff = 0;
            int count = 1;
            for (int i = 0; i < nums.length; i++) {
                //得到当前差值
                currDiff = nums[i] - nums[i-1];
                if ((currDiff>0&&preDiff<=0)||(currDiff<0&&preDiff>=0)){
                    count++;
                    preDiff = currDiff;
                }

            }
            return count;
        }
    }
}
